package com.feicheng.iou.result;

import com.alibaba.fastjson.JSONObject;
import com.feicheng.iou.bean.InformationBean;
import com.feicheng.iou.commom.ReturnCode;
import com.feicheng.iou.constant.StatusCodeConstant;
import com.feicheng.iou.util.CusStringUtil;
import com.feicheng.iou.util.ReadPropertiesUtil;
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;

import java.io.Serializable;
import java.util.Properties;

/**
 * @Author tianchunlei
 * @Des //v1.0.0版本统一返回
 * @Date 2021/8/5
 **/
public class ResultInfoV110 extends JSONObject {

    //获取程序当前路径下的文件
    public static final Properties properties = ReadPropertiesUtil
            .getProperties("/information.properties");

    /**
     * @return
     * @Author tianchunlei
     * @Description //成功的返回
     * @Date 2021/8/5 15:50
     * @Param
     */
    private ResultInfoV110() {
        this.put("CODE", StatusCodeConstant.I001);
        this.put("MESSAGE", properties.get(StatusCodeConstant.I001));
        this.put("STATUS", "SUCCESS");
    }

    /**
     * @return
     * @Author tianchunlei
     * @Description //给定数据返回成功
     * @Date 2021/8/5 15:57
     * @Param
     */
    private ResultInfoV110(Object data) {
        this.put("CODE", StatusCodeConstant.I001);
        this.put("MESSAGE", properties.get(StatusCodeConstant.I001));
        this.put("DATA", data);
        this.put("STATUS", "SUCCESS");
    }

    /**
     * @return
     * @Author tianchunlei
     * @Description //指定code和message的返回形式
     * @Date 2021/8/5 16:34
     * @Param
     */
    private ResultInfoV110(String code, String msg) { //响应ERROR和LOGIN_FAIL
        this.put("CODE", code);
        this.put("MESSAGE", msg);

        if (code.contains("F")) {
            this.put("STATUS", "FAIL");
        }
        if (code.equals("F003")) {
            this.put("STATUS", "LOGIN_FAIL");
        }
        if (code.contains("E")) {
            this.put("STATUS", "ERROR");
        }
        if (code.contains("W")) {
            this.put("STATUS", "WARN");
        }
    }

    public static ResultInfoV110 success() {
        return new ResultInfoV110();
    }

    public static ResultInfoV110 success(Object data) {
        return new ResultInfoV110(data);
    }

    public static ResultInfoV110 failOrError(String code, String msg) {
        return new ResultInfoV110(code, msg);
    }

}
